import type { UserInfo } from '@/api/system/model/userModel'
import { defineStore } from 'pinia'

interface IUserStore {
  openId: Nullable<string>
  userInfo: Nullable<UserInfo>
  token: Nullable<string>
}

export const useUserStore = defineStore({
  id: 'user',
  state: (): IUserStore => ({
    openId: null,
    token: null,
    userInfo: null,
  }),
  getters: {},
  actions: {
    setOpenId(data: Nullable<string>) {
      this.openId = data
    },
    setToken(data: Nullable<string>) {
      this.token = data
    },
    setUserInfo(data: Nullable<UserInfo>) {
      this.userInfo = data
    },
    logout() {
      this.userInfo = null
      this.token = null
    },
  },

  // 开始数据持久化
  persist: true,
})
